<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" scroll="no">
<%@ taglib prefix="ef" uri="control"%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>角色管理</title>
<link rel="shortcut icon" href="${res}favicon.ico" type="image/x-icon" />
 <!--Basic Styles-->
<link href="../framework/css/font.css" rel="stylesheet" />
<link href="../framework/miniui/themes/material/miniui.css" rel="stylesheet" />
<link href="../framework/css/app.min.1.css" rel="stylesheet" type="text/css" />
<link href="../framework/css/app.min.2.css" rel="stylesheet" type="text/css" />
<script src="../framework/main.js" type="text/javascript"></script>
<style type="text/css">html, body{margin:0;padding:0;border:0;width:100%;height:100%;overflow:hidden;}</style>
<script>
Page.onLoad(function(){
	
});

function onTreeClickBranch(e){
	var code = e.node.BranchInnerCode;
	mini.get('roleTree').load({BranchInnerCode:code});
}

var newQueryString = null;
function onRoleTreeClick(e){
	newQueryString = "Type=MR&ID="+e.node.ID;
	mini.get('mainTabs').tryReload(newQueryString);
}

function onBranchTreeLoad(e){
	if(e.sender.getRootNode().children.length > 0){
		e.sender.selectNode(e.sender.getRootNode().children[0]);
	}
}

function onTabsActiveChanged(e){
	e.sender.tryReload(newQueryString, e.sender.getTab(e.index));
}

function add(){
	mini.open({
		width : 530,
		height : 350,
		title : '添加角色',
		url : "${ctx}mhr/roleAddDialog.jhtml?BranchInnerCode="+ mini.get('branchTree').getSelectedNode().ID,
		onOk : addSave,
		onLoad : function(){
			try{
				$DW.$('#RoleName').focus();
			}catch(e){}
		}
	});
}

function addSave(){
	var form = $DW.mini.getForm('form2');
	if(form.isValid() == false){
		return;
	}
	var data = form.getData();
	Server.sendRequest("MemberRole.add",data,function(response){
		if(response.Status == 1){
			top.mini.showTips({content:response.Message,state:'success'});
			var roleTree = mini.get('roleTree');
			roleTree.reload(function(){
				roleTree.selectNode(roleTree.getNode(data.RoleCode));
			});
			$D.close();
		}else{
			top.mini.warn(response.Message);
		}
	});
}

function del(){
	var node = mini.get('roleTree').getSelectedNode();
 	if(!node){
 		top.mini.showTips({content:'@{Common.PleaseSelectToDeleteRowFirst}',state:'info'});
		return ;
	}
	top.mini.confirm("确认删除  <b style='color:#F00'>"+node.RoleName+"</b> ？",function(action){
		 if (action == "ok") {
			Server.sendRequest("MemberRole.del",{ID:node.ID},function(response){
				if(response.Status == 1){
					top.mini.showTips({content:response.Message,state:'success'});
					mini.get('roleTree').reload();
				}else{
					top.mini.warn(response.Message);
				}
			});
		 };
	});
}

function edit(){
	var node = mini.get('roleTree').getSelectedNode();
 	if(!node){
 		top.mini.showTips({content:'@{Common.PleaseSelectRowFirst}',state:'info'});
		return ;
	}
	mini.open({
		width : 530,
		height : 350,
		title : '角色编辑',
		url : "${ctx}mhr/roleAddDialog.jhtml?ID="+node.ID + "&readonly=readonly",
		onOk : editSave,
		onLoad : function(){
			$DW.$('#RoleCode').disable();
			$DW.$('#BranchID').disable();
			try{
				$DW.$('#RoleName').focus();
			}catch(e){}
		}
	});
}

function editSave(){
	var form = $DW.mini.getForm('form2');
	if(form.isValid() == false){
		return;
	}
	var data = form.getData();
	Server.sendRequest("MemberRole.save",data,function(response){
		if(response.Status == 1){
			top.mini.showTips({content:response.Message,state:'success'});
			var roleTree = mini.get('roleTree');
			roleTree.reload(function(){
				roleTree.selectNode(roleTree.getNode(data.RoleCode));
			});
			$D.close();
		}else{
			top.mini.warn(response.Message);
		}
	});
}
</script>
</head>
<body class="body-list">
<div id="layout1" class="mini-layout" style="width:100%;height:100%;">
 	<div region="west" width="220" showheader="false" allowResize="false">
 		<div style="height:50%">
 			<div class="mini-toolbar">
	            <a class="mini-button" iconCls="icon-branch"  plain="true">修改组织机构</a>
			</div>
			<div class="mini-fit" style="padding-top:3px;">
				<ul id="branchTree" class="mini-tree" expandOnLoad="1" onload="onBranchTreeLoad" onnodeclick="onTreeClickBranch" style="width:100%;" textField="Name" idField="BranchInnerCode" parentField="ParentID" resultAsTree="false" showTreeIcon="true" method="MemberBranch.tree" ></ul>
			</div>
 		</div>
 		<div style="height:50%;">
 			<div class="mini-toolbar" plain="true" style="box-shadow: 0 2px 5px rgba(0, 0, 0, 0.16), 0 2px 10px rgba(0, 0, 0, 0.12);">
	           <a class="mini-button" iconCls="icon-add" plain="true" onClick="add()">新建</a>
			    <a class="mini-button" iconCls="icon-edit" plain="true" onClick="edit()">编辑</a>
			    <a class="mini-button" iconCls="icon-remove" plain="true" onClick="del()">删除</a>
			</div>
			<div class="mini-fit" style="padding-top:5px;">
				<ul id="roleTree" class="mini-tree" onnodeclick="onRoleTreeClick" style="width:100%;" textField="RoleName" idField="ID" resultAsTree="false" showTreeIcon="true" method="MemberRole.bindTree" ></ul>
			</div>
 		</div>
    </div>
     <div title="center" region="center" >
		<div id="mainTabs" class="mini-tabs" style="width:100%;height:100%;" plain="false" onbeforeactivechanged="onTabsActiveChanged">
             <div title="基本信息" url="roleInfo.jhtml" iconCls="icon-job-title"></div>
             <div title="菜单权限" url="menuPriv.jhtml" iconCls="icon-menu"></div>
         </div>
    </div>
</div>
</body>
</html>